<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml"
      xmlns:th="http://www.thymeleaf.org">
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="/css/yoyoga.css" media="all"/>
    <script type="text/javascript" src="/layui/layui.js"></script>
    <script type="text/javascript" src="/libs/jquery.min.js"></script>

    <!-- 注意：此页面仅教练能看到 -->
</head>
<body>

<div class="layui-tab main-content-container">
    <ul class="layui-tab-title" style="width: 100%;">
        <li class="layui-this" onclick="showContract(0,'contractListWait')">待处理</li>
        <li onclick="showContract(1,'contractListOnGoing')">进行中</li>
        <li onclick="showContract(3,'contractListFinished')">已结束</li>
        <li onclick="showContract(2,'contractListReject')">已拒绝</li>
        <li onclick="showContract(4,'contractListCancel')">已取消</li>
    </ul>
    <div class="layui-tab-content"  style="width: 100%;">
        <div class="layui-tab-item layui-show" id="contractListWait"></div>
        <div class="layui-tab-item" id="contractListOnGoing"></div>
        <div class="layui-tab-item" id="contractListFinished"></div>
        <div class="layui-tab-item" id="contractListReject"></div>
        <div class="layui-tab-item" id="contractListCancel"></div>
    </div>
</div>



<script>
    layui.use('element', function() {
        var element = layui.element; //导航的hover效果、二级菜单等功能，需要依赖element模块

        //监听导航点击
        element.on('nav(demo)', function(elem) {
            //console.log(elem)
            layer.msg(elem.text());
        });
    });
</script>

<script>
    //展示合同信息
    function showContract(cState,id){
        layui.use('flow', function() {
            var flow = layui.flow;
            flow.load({
                elem: '#'+id, //流加载容器
                done: function(page, next) { //执行下一页的回调
                    var lis = [];
                    var contractState;
                    $.ajax({
                        url:"/contract/select?page="+page+"&cState="+cState,
                        dataType:"json",
                        success:function(res){
                            layui.each(res.currentMessage,function (index, item) {
                                contractState = contractStateName(item.contract.cState);
                                lis.push(
                                    '<div class="mytrainer-card" onclick="toDetail('+JSON.stringify(item).replace(/\"/g,"'")+')">'
                                    +'<div class="mytrainer-card-left">'
                                    +'<div class="mytrainer-card-gym-trainer">'
                                    +'<p>场馆:'+item.gym.gName+'</p>'
                                    +'</div>'
                                    +'<div class="mytrainer-card-gym-trainer">'
                                    +'学员：'+item.student.sName
                                    +'</div>'
                                    +'<div class="mytrainer-card-gym-trainer">'
                                    +'课时费：'+item.contract.cBanlance
                                    +'</div>'
                                    +'<div class="mytrainer-card-gym-trainer">'
                                    +'合约发起时间'+item.contract.cCreatetime
                                    +'</div>'
                                    +'</div>'
                                    +'<div class="mytrainer-card-right">'
                                    +contractState
                                    +'</div>'
                                    +'</div>'
                                )
                            });
                            next(lis.join(''), page < res.total);
                        }
                    })

                }
            });
        });
    }

    $(function () {
        showContract(0,'contractListWait');
    });

    function toDetail(contractData) {
        console.log(contractData);
        var form = document.createElement("form");
        form.action = "/contract/toContractDetail";
        form.method = "post";
        form.style.display = "none";
        document.body.appendChild(form);
        var opt = document.createElement("textarea");
        opt.name ="contractData" ;
        opt.value = JSON.stringify(contractData);
        form.appendChild(opt);
        document.body.appendChild(form);
        form.submit();
        return form;
    }

    function contractStateName(state){
        switch (state) {
            case 0:
                return '去处理';
            case 1:
                return "进行中";
            case 2:
                return "已拒绝";
            case 3:
                return "已完成";
            case 4:
                return "已取消";
        }
    }

</script>





</body>

</html>
